const app = getApp();
var api = require('../../../api.js');
var mta = require('../../../mta_analysis.js');

Page({
  data: {
    truename: '',
    mobile: '',
  },
  onLoad: function (options) {

    app.bind();
    this.getinfo();

    mta.Page.init();
  },
  onReady: function () {
  
  },
  onShow: function () {
  
  },
  onHide: function () {
  
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
  
  },
  getinfo: function (e) {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    wx.request({
      url:api.user.info,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
      },
      success: function (e) {
        console.log(e);
        var list = e.data.data;
        console.log(list);
        if (e.data.code == 0) {
          that.setData({
            truename: e.data.data.truename,
            mobile: e.data.data.mobile
          })
        } else {
          wx.navigateTo({
            url: '/pages/grant/grant'
          })
        }
      }
    });
  },
  modify: function (e) {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    var trueName = that.data.truename;
    var mobile = that.data.mobile;
    wx.request({
      url:api.user.editInfo,
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        truename: trueName,
        mobile: mobile,
      },
      success: function (e) {
        console.log(e);
      }
    });
  },
  name: function (e) {
    // console.log(e);
    var name = e.detail.value;
    this.setData({
      truename: name
    })
  },
  mobile: function (e) {
    var mobile = e.detail.value;
    this.setData({
      mobile: mobile
    })
  },
})